#!/usr/bin/env python
# -*- coding: utf-8 -*-
from os import spawnl, P_NOWAIT, system,sep
from sys import argv
from commands import getstatusoutput
from os.path import realpath, split as path_split
try:
    import pygtk
    pygtk.require("2.0")
except:
    pass
try:
    import gtk
    import pango
    import gtk.glade
    import gobject
except:
    sys_exit(1)

from selenesearch import open_browser

def __quit(*args):
    if me.get_widget("checkbutton1").get_active():
        spawnl(P_NOWAIT, argv[2])
    gtk.main_quit()

def __ala(widget):
    open_browser(widget.get_uri())

me = gtk.glade.XML(realpath(path_split(argv[0])[0])+sep+"bug.glade")
dic = {"on_dialog1_response" : __quit,
       "on_dialog1_close" : __quit,
       "on_linkbutton1_clicked" : __ala,
               }
if len(argv)<3:
    me.get_widget("checkbutton1").set_property("visible",False)
if len(argv)<2:
    info = "No data given."
else:
    info = str(argv[1].replace("\\n","\n"))

me.get_widget("textview1").get_buffer().set_text(info)
me.signal_autoconnect(dic)
me.get_widget("dialog1").show()
gtk.main()
